package com.lcj.bff.driver.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.lcj.bff.driver.controller.form.CanPayForm;
import com.lcj.bff.driver.controller.form.PayFineForm;
import com.lcj.bff.driver.controller.form.SearchFineForm;
import com.lcj.bff.driver.service.FineService;
import com.lcj.common.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.HashMap;

@RestController
@RequestMapping("/fine")
@Tag(name = "FineController", description = "罚款接口")
public class FineController {

    @Resource
    private FineService fineService;

    @PostMapping("/searchFineByPage")
    @Operation(description = "分页查询罚款列表")
    @SaCheckLogin
    public Result searchFineByPage(@RequestBody @Valid SearchFineForm form) {
        Long driverId = StpUtil.getLoginIdAsLong();
        form.setDriverId(driverId);
        Result result = fineService.searchFineByPage(form);
        return result;
    }

    @PostMapping("/canPay")
    @Operation(description = "判断是否能支付")
    public Result canPay(@RequestBody @Valid CanPayForm form) {
        form.setDriverId(StpUtil.getLoginIdAsLong());
        Result result = fineService.canPay(form);
        return result;
    }

    @PostMapping("/payFine")
    @Operation(description = "支付罚款")
    public Result payFine(@RequestBody @Valid PayFineForm form) {
        form.setDriverId(StpUtil.getLoginIdAsLong());
        Result result = fineService.payFine(form);
        return result;
    }

}
